const gulp = require('gulp');
const babel = require('gulp-babel');
const typescript = require('gulp-typescript');
const tsProject = typescript.createProject('tsconfig.json');
const del = require('del');

const paths = {
  ts: {
    src: ['src/**/*.ts'],
    dest: 'dist'
  },
  js: {
    src: ['src/**/*.js'],
    dest: 'dist'
  },
  packagejson: {
    src: ['package.json'],
    dest: 'dist'
  },
};

function clean() {
  return del(['dist']);
}

function packagejson() {
  return gulp.src(paths.packagejson.src)
    .pipe(gulp.dest(paths.packagejson.dest));
}


function js() {
  return gulp.src(paths.js.src)
    .pipe(babel({
      presets: ['@babel/env']
    }))
    .pipe(gulp.dest(paths.js.dest));
}

function ts() {
  return gulp.src(paths.ts.src)
    .pipe(tsProject())
    .js.pipe(gulp.dest(paths.ts.dest));
}

function watch() {
  gulp.watch(paths.js.src, js);
  gulp.watch(paths.ts.src, ts);
}

let build = gulp.series(clean, gulp.parallel(packagejson, js, ts))
let dev = gulp.series(build, watch)

exports.dev = dev
exports.build = build
exports.default = build